/*
 * File      : spi_flash_w25qxx.h
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2011-12-16     aozima      the first version
 */

#ifndef SPI_VS10X3_H_INCLUDED
#define SPI_VS10X3_H_INCLUDED

#include <rtthread.h>
#include <drivers/spi.h>
#include "stm32f10x.h"

#define FFT_BANS_NUMBER		23

#define CLOCK_REG       0xc3e8          //0xc00 is fow VS1003 or higher version

/*******************************/

#define VS10X3_XCS_PIN			GPIO_Pin_12
#define VS10X3_XCS_PORT			GPIOB

#define VS10X3_XDCS_PIN			GPIO_Pin_6
#define VS10X3_XDCS_PORT		GPIOC

#define VS10X3_XRESET_PIN		GPIO_Pin_0
#define VS10X3_XRESET_PORT		GPIOE

#define VS10X3_DREQ_PIN			GPIO_Pin_7
#define VS10X3_DREQ_PORT		GPIOC

/*******************************/

#define VS10X3_XCS_H()			GPIO_SetBits(VS10X3_XCS_PORT,VS10X3_XCS_PIN)
#define VS10X3_XCS_L()			GPIO_ResetBits(VS10X3_XCS_PORT,VS10X3_XCS_PIN)

#define VS10X3_XDCS_H()			GPIO_SetBits(VS10X3_XDCS_PORT,VS10X3_XDCS_PIN)
#define VS10X3_XDCS_L()			GPIO_ResetBits(VS10X3_XDCS_PORT,VS10X3_XDCS_PIN)

#define VS10X3_XRESET_H()		GPIO_SetBits(VS10X3_XRESET_PORT,VS10X3_XRESET_PIN)
#define VS10X3_XRESET_L()		GPIO_ResetBits(VS10X3_XRESET_PORT,VS10X3_XRESET_PIN)

#define VS10X3_DREQ_H()			GPIO_SetBits(VS10X3_DREQ_PORT,VS10X3_DREQ_PIN)
#define VS10X3_DREQ_L()			GPIO_ResetBits(VS10X3_DREQ_PORT,VS10X3_DREQ_PIN)

enum
{
	VS10X3_STOP=0,
	VS10X3_READ_DECODE_TIME,
	VS10X3_RESET_DECODE_TIME,
	VS10X3_GET_SPECM,
	VS10X3_SET_BANDS,			
};

struct spi_codec_device
{
    struct rt_device               codec_device;
    rt_uint16_t   				   reg_value;
    struct rt_spi_device           *rt_spi_device;
};

extern uint8_t vs10x3_read_status(void);
extern rt_err_t vs10x3_codec_init(const char *codec_device_name,
                            const char *spi_device_name);


#endif // SPI_FLASH_W25QXX_H_INCLUDED
